import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRecordList, DataRes} from '@/api/config'
import {BasePhysicalExamination} from './index'
import {Operation as Opr} from '@/components/dTable/dTable'

/**
 * @description: 非免疫规划预防接种史
 * @return {*}
 */
export interface VaccinationHistory extends BasePhysicalExamination {
  inocName: string // 疫苗名称
  inocDate: string // 接种时间
  unitsName: string // 接种机构名称
  operation?: Array<Opr>
}

/**
 * @description: 保存非免疫规划预防接种史
 * @param {VaccinationHistory} data
 * @return {*}
 */
export const saveVaccinationHistory = (data: Array<VaccinationHistory>): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/vaccinationHistory/save',
    method: 'post',
    data
  })
}

/**
 * @description: 根据体检登记表id获取非免疫规划预防接种史数据
 * @param {string} checkupRegisterId  //  checkupRegisterId 体检登记表id
 * @return {*}
 */
export const getVaccinationHistory = (checkupRegisterId: string): AxiosPromise<DataRes<Array<VaccinationHistory>>> => {
  return request({
    url: `/api/vaccinationHistory/get/${checkupRegisterId}`,
    method: 'get'
  })
}

/**
 * @description: 拒检非免疫规划预防接种史
 * @param {BasePhysicalExamination} data
 * @return {*}
 */
export const rejectVaccinationHistory = (data: Array<BasePhysicalExamination>): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/vaccinationHistory/reject',
    method: 'post',
    data
  })
}

// 疫苗库分页查询
export interface VaccineStoreParams {
  inocCode?: string // 疫苗代码
  inocName?: string // 疫苗名称
  page?: number
  limit?: number
}
// 疫苗库列表
export interface VaccineStoreList {
  id?: string
  inocCode?: string // 疫苗代码
  inocName?: string // 疫苗名称
  pinyinCode?: string | null // 拼音码
  unitsName?: string | null // 接种机构
}

/**
 * @description: 疫苗库分页查询
 * @param {VaccineStoreParams} data
 * @return {*}
 */
export const getVaccineStore = (params: VaccineStoreParams): AxiosPromise<DataRecordList<VaccineStoreList>> => {
  return request({
    url: '/api/vaccineStore/page',
    method: 'get',
    params
  })
}

/**
 * @description: 保存疫苗库信息
 * @param {VaccineStoreList} data
 * @return {*}
 */
export const saveVaccineStore = (data: VaccineStoreList): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/vaccineStore/save',
    method: 'post',
    data
  })
}

/**
 * @description: 删除疫苗库信息
 * @param {string} id 疫苗id
 * @return {*}
 */
export const deleteVaccineStore = (id: string): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: `/api/vaccineStore/remove/${id}`,
    method: 'post'
  })
}

/**
 * @description: 搜索疫苗库数据
 * @param {object} params   inocName 疫苗名称
 * @return {*}
 */
export const getVaccineStoreByName = (params: {inocName: string}): AxiosPromise<DataRes<Array<VaccineStoreList>>> => {
  return request({
    url: '/api/vaccineStore/list',
    method: 'get',
    params
  })
}
